package com.power.controller.DefectAd;

import com.alibaba.fastjson.JSONObject;
import com.power.common.Contants;
import com.power.ov.ResultData;
import com.power.ov.ResultDataTable;
import com.power.pojo.Defecttype;
import com.power.service.DefectAdService;
import com.power.service.impl.defectAdServiceImpl;
import com.power.utils.WriterUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created/**
 * Created with IntelliJ IDEA.
 * User: lh
 * Date: 2020/09/29 21:01
 * Description:
 * Version: V1.0
 */
@WebServlet("/addType.do")
public class addServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        BufferedReader br=req.getReader();
        String string=br.readLine();
        Defecttype defecttype= JSONObject.parseObject(string,Defecttype.class);
        DefectAdService defectAdService=new defectAdServiceImpl();
        resp.setContentType("application/json;charset=utf-8");
        ResultDataTable resultData = new ResultDataTable();
        int result =0;
        try {
            result=defectAdService.addDefecttype(defecttype);
            if (result > 0){
                resultData.setCode(200);
                resultData.setMessage("添加成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(JSONObject.toJSONString(resultData));
        resp.getWriter().flush();
        resp.getWriter().close();


    }
}
